﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExtAspNet;

namespace HY.WEB.SA
{
    public partial class tel_view : PageBase
    {
        public string us, whe = "", path = "";           
        protected void Page_Load(object sender, EventArgs e)
        {
            us = Session["ID"].ToString();
            if (!IsPostBack)
            {
                if (!String.IsNullOrEmpty(Request["sid"]))
                {
                     hidsid.Text = Request["sid"].Trim();                
                }
             
                fill2();
            }

        
        }

        void movenext(string val)
        {
            string comp="";
            string sid=hidsid.Text;
            DataTable dtt = DAL.DbHelperSQL.SqlDataAdapter("select * from comp_tel where sid=" + sid + " order by sid ");
           
            if (dtt.Rows.Count > 0)
            {
                comp = dtt.Rows[0]["cbh"].ToString().Trim();            
            }


            dtt = DAL.DbHelperSQL.SqlDataAdapter("select * from comp_tel where cbh='" + comp + "' order by sid ");
        
              for (int i=0; i < dtt.Rows.Count;i++)
                {
                    if (sid == dtt.Rows[i]["sid"].ToString().Trim())
                    {
                        if (val == "+" & i < dtt.Rows.Count-1)
                             hidsid.Text = dtt.Rows[i + 1]["sid"].ToString().Trim();
                        if (val == "-" & i >0)
                            hidsid.Text = dtt.Rows[i-1]["sid"].ToString().Trim();
                        break;
                    }

                }

              Response.Redirect("tel_view.aspx?sid=" + hidsid.Text + "");

        }

        void fill2()
        {

            BLL.CO.comp_tel S = new BLL.CO.comp_tel();
 
          DataTable d=  S.GetList("sid="+hidsid.Text).Tables[0];

          hidsid.Text = d.Rows[0]["sid"].ToString().Trim();
        //  hidbh.Text = d.Rows[0]["jbh"].ToString().Trim();

          lblcomp.Text = d.Rows[0]["cname"].ToString().Trim();
          lbltel.Text = d.Rows[0]["tel"].ToString().Trim();

          lblperson.Text = d.Rows[0]["person"].ToString().Trim();

          date1.Text = d.Rows[0]["pdtime"].ToString().Trim();

          lblmemo.Text = Server.HtmlDecode(d.Rows[0]["pmemo"].ToString().Trim());
          }

   


      protected void btndel_Click(object sender, EventArgs e)
        {
            movenext("-");

        }

  protected void btnadd_Click(object sender, EventArgs e)
        {
            movenext("+");

        }
    }
}